short int valA0;
short int tempx;

void setup() {
  Serial.begin(9600);
}

void loop() {
  valA0 = analogRead(A0);

  if(valA0 >= 880 && valA0 <= 960){
    tempx = convert(valA0, 960, 880, -20, 0);
    Serial.println( valA0 );
    Serial.println( tempx ); 
  }
  else if(valA0 >= 740 && valA0 <= 880){
    tempx = convert(valA0, 880, 740, 0, 20);
    Serial.println( valA0 );
    Serial.println( tempx );
  } 
  else if(valA0 >= 560 && valA0 <= 740){
    tempx = convert(valA0, 740, 560, 20, 40);
    Serial.println( valA0 );
    Serial.println( tempx ); 
  }
  else if(valA0 >= 400 && valA0 <= 560){
    tempx = convert(valA0, 560, 400, 40, 60);
    Serial.println( valA0 );
    Serial.println( tempx );
  } 
  else if(valA0 >= 280 && valA0 <= 400){
    tempx = convert(valA0, 400, 280, 60, 80);
    Serial.println( valA0 );
    Serial.println( tempx ); 
  }
  else if(valA0 >= 180 && valA0 <= 280){
    tempx = convert(valA0, 280, 180, 80, 100);
    Serial.println( valA0 );
    Serial.println( tempx ); 
  }
}

short int convert(short int ax, short int a0,short int a1, short int temp0,short int temp1){
   short int tempx;
   tempx = temp0+(ax-a0)*(temp1-temp0)/(a1-a0);
   return tempx;
}

